<?php
/**
 * @copyright   2008-2014 简好网络 <http://www.phpshe.com>
 * @creatdate   2012-0501 koyshe <koyshe@gmail.com>
 */
$menumark = 'ad';
function xiehuiname($xiehuiid){
    global $db;
    $xiehuiname = $db->pe_select('xiehui',array('xiehui_id'=>$xiehuiid));
    return $xiehuiname['xiehui_name'];
}
switch ($act) {
    //#####################@ 添加背景轮播图 @#####################//
    case 'add':
        if (isPost()) {
            if ($_FILES['lunbo_img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['lunbo_img']);
                $_p_info['ad_img'] = $upload->filehost;
            }
            if ($db->pe_insert('ad', pe_dbhold($_p_info))) {
                pe_success('添加成功!', 'admin.php?mod=ad');
            }
            else {
                pe_error('添加失败...');
            }
        }
        include(pe_tpl('ad_add.html'));
        break;
    //#####################@ 修改广告 @#####################//
    case 'edit':
        $ad_id = intval($_g_id);
        if (isPost()) {
            if ($_FILES['lunbo_img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['lunbo_img']);
                $_p_info['ad_img'] = $upload->filehost;
            }
            if ($db->pe_update('ad', array('ad_id'=>$ad_id), pe_dbhold($_p_info))) {
                pe_success('修改成功!', 'admin.php?mod=ad');
            }
            else {
                pe_error('修改失败...');
            }
        }
        $ad = $db->pe_select('ad', array('ad_id'=>$ad_id));
        include(pe_tpl('ad_edit.html'));
        break;
    //#####################@ 广告排序 @#####################//
    case 'order':
        pe_token_match();
        foreach ($_p_ad_order as $k=>$v) {
            $result = $db->pe_update('ad', array('ad_id'=>$k), array('ad_order'=>$v));
        }
        if ($result) {
            //cache_write('ad');
            pe_success('排序成功!');
        }
        else {
            pe_error('排序失败...');
        }
        break;
    //#####################@ 广告删除 @#####################//
    case 'del':
        pe_token_match();
        if ($db->pe_delete('ad', array('ad_id'=>is_array($_p_ad_id) ? $_p_ad_id : $_g_id))) {
            //cache_write('ad');
            pe_success('删除成功!');
        }
        else {
            pe_error('删除失败...');
        }
        break;
    //#####################@ 广告状态 @#####################//
//	case 'state':
//		pe_token_match();
//		if ($db->pe_update('ad', array('ad_id'=>is_array($_p_ad_id) ? $_p_ad_id : $_g_id), array('ad_state'=>$_g_state))) {
//			cache_write('ad');
//			pe_success("操作成功!");
//		}
//		else {
//			pe_error("操作失败...");
//		}
//	break;
    //#####################@ 广告列表 @#####################//
    default :
        $info_list = $db->pe_selectall('ad');
        $seo = pe_seo($menutitle='轮播列表', '', '', 'admin');
        include(pe_tpl('ad_list.html'));
        break;
}
?>